import pytest
import requests
from config import BASE_URL

test_data = [("admin", "HM_2023_test", 200, "成功"),
             ("", "HM_2023_test", 500, "错误"),
             ("admin", "", 500, "错误"),
             ]
# 定义类方法
class TestLogin:

    # 前置
    def setup_method(self):
        # 获取验证码
        response = requests.get(BASE_URL + "/api/captchaImage")
        self.uuid = response.json()["uuid"]

    @pytest.mark.parametrize("username, password, code, msg", test_data)
    def test_login(self, username, password, code, msg):
        url = BASE_URL + "/api/login"
        data = {
            "username": username,
            "password": password,
            "code": "2",
            "uuid": self.uuid
        }
        response = requests.post(url, json=data)
        print(response.json())
        assert response.status_code == 200
        assert response.json()["code"] == code
        assert msg in response.json()["msg"]
